<?php
class ABapi{
	static function redirect($s_url, $b_add = false){
		$s_url = $b_add ? HOST_NAME.$s_url:$s_url;
		header("Location:$s_url");
		die($s_url);
	}

	static function make_params($m_array){
		$a_array = ABApi::params($m_array);
		$s_param = '';
		foreach($a_array as $s_key => $s_value){
			$s_param .= " $s_key=\"$s_value\"";
		}
		return $s_param;
	}

	static function params($m_args){
		if(is_array($m_args))return $m_args;
		if(empty($m_args))return array();
		$a_tmp = array();
		$a_args = explode(',', $m_args);
		foreach($a_args as $s_val){
			$a_var = explode(':', $s_val);
			$a_tmp[trim($a_var[0])] = trim($a_var[1]);
		}
		return $a_tmp;
	}
	
	static function obj2array($o_obj, $s_var){
		return array_map(create_function('$o_obj', "return \$o_obj->$s_var;"), $o_obj);
	}

	static function trace(){
		$fp = fopen(PATH_LOGFILE, 'a');
		$a_var = func_get_args();
		foreach ($a_var as $s_value) {
			fwrite($fp, "$s_value \n");
		}
		fclose($fp);
	}

	static function encodeURL($s_str){
		$text=strtolower($s_str);
		return str_replace(' ', '-', $text);
	}
	
	static function filterParam($s_str){
		return  str_replace('-', ' ', $s_str);
	}
	
	static function checkCanGzip(){
		if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) return 'x-gzip';
		if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) return 'gzip';
		return false;
	}
	
	static function doGzip($Proccess, $level = 9){
		$Temp =  "\x1f\x8b\x08\x00\x00\x00\x00\x00";
		$Size = strlen($Proccess);
		$Crc = crc32($Proccess);
		$Contents = gzcompress($Proccess, $level);
		unset($Proccess);
		$Contents = substr($Contents, 0, strlen($Contents) - 4);
		return $Temp . $Contents . pack('V', $Crc). pack('V', $Size);
	}
}
?>
